Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virttools: add new test type and virt-install test #3923

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

smitterl
Copy link
Contributor

@smitterl smitterl commented Dec 9, 2021

Depends on avocado-vt PR avocado-framework/avocado-vt#3270

  1. /virttools:
    Add new test type for tools from virt-manager repository; by
    using avocado-vt we get access to many useful test functions
    ready to use for qemu/libvirt testing. The test type assumes
    the same default setup as for tp-libvirt/libvirt and builds
    on top of that. During testing, switching from a bootstrapped
    libvirt environment to a bootstrapped virttools environment
    worked and the test case passed.
  2. hostdev_mdev:
    Add a new test case.
    a. 'run': This virt-install test case is currently ccw device
    specific but other types on other platforms can be
    implemented by creating a subclass for the
    MdevHandler for the desired mdev_type.
    b. 'clean_up/sleep': The introduction of 1sec sleep is
    necessary to make sure setting the device offline will
    work. Using the usual 'wait_for' here seemed to
    overcomplicate the code.
    c. 'virt_install_with_hostdev': The function hardcodes several
    vm installation parameters. This is to keep the code
    simple at this point but can be changed in the future.
  3. spell.ignore:
    Add command and device names used in ccw.py and hostdev_mdev.py.
  4. ccw.py:
    Add a new function to set devices offline to reset them to their
    previous state. Test cases with real ccw devices usually assume
    the test environment is configured in a way that the first unused
    ccw device will be used for the test case, possibly in a
    destructive way. Some functions have been added return value 'True'
    on success to allow for usage in 'wait_for' constructions.
  5. README.md:
    Add readme file to give a bit more context and intention for the
    new test type.

Signed-off-by: Sebastian Mitterle [email protected]

@smitterl
Copy link
Contributor Author

smitterl commented Dec 9, 2021

Test run

# avocado run --vt-type virttools --vt-machine-type s390-virtio --vt-connect-uri qemu:///system virt_install.hostdev.mdev
JOB ID     : 9a063022d47f0f96f4cc438878e3fdaba8db872d
JOB LOG    : /root/avocado/job-results/job-2021-12-09T06.12-9a06302/job.log
 (1/1) type_specific.io-github-autotest-libvirt.virt_install.hostdev.mdev.check_present_inside_guest: PASS (17.59 s)
RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME   : 17.91 s

@smitterl
Copy link
Contributor Author

smitterl commented Dec 9, 2021

Regression coverage for changes in ccw.py:

# avocado run --vt-type libvirt --vt-machine-type s390-virtio --vt-connect-uri qemu:///system libvirt_ccw_passthrough
JOB ID     : be82f5b0b4906dcc2857bec16dfeb0e554e27f48
JOB LOG    : /root/avocado/job-results/job-2021-12-09T06.17-be82f5b/job.log
 (1/3) type_specific.io-github-autotest-libvirt.libvirt_ccw_passthrough.read_write.happy_path: PASS (49.78 s)
 (2/3) type_specific.io-github-autotest-libvirt.libvirt_ccw_passthrough.happy_path: PASS (33.68 s)
 (3/3) type_specific.io-github-autotest-libvirt.libvirt_ccw_passthrough.device_removal: PASS (50.45 s)
RESULTS    : PASS 3 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME   : 134.35 s

@smitterl
Copy link
Contributor Author

smitterl commented Dec 9, 2021

@dzhengfy @chunfuwen @Yingshun Please, can you help review?

@smitterl smitterl force-pushed the virt_tools_single_commit branch 2 times, most recently from 31031c7 to 73a563f Compare December 9, 2021 17:29
@dzhengfy dzhengfy added the depend on The PR has dependency on other PRs label Dec 16, 2021
Copy link
Contributor

@dzhengfy dzhengfy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others LGTM

raise NotImplementedError()

@staticmethod
def from_type(mdev_type):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the function name is not very meaningful and explicit. Could we use one similar like 'get_instance_from_type()'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dzhengfy I would like to maintain it, IMO, it's a common python idiom, please check https://github.com/avocado-framework/avocado-vt/pull/2610/files#r445400984

ccw.set_device_offline(self.device_id)


def disk_for_import(vmxml):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To align the naming style for functions in your codes, I suggest we name this function beginning with a verb, like 'get_disk_for_import()'. But the decision depends on you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it.

return first_disk.find('source').get('file')


def first_mdev_nodedev_name():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_first_mdev_nodedev_name()? But this decision depends on you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it.


session = vm.wait_for_login()
handler.check_device_present_inside_guest(session)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to close the session.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The session is closed now in the final clause handler.clean_up.

raise TestError("Test doesn't know how to handle %s." % mdev_type)


class CcwMdevHandler(MdevHandler):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving CcwMdevHandler and MdevHandler to provider? I wonder if they can be used by other tests...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yingshun At this point the base class doesn't do anything but only serves as interface to be implemented. Especially the get_target_address method at this point to me looks rather test specific. I'm not sure if somebody found those classes below the provider path they would know what to do with them without the context of the test implementation. Therefore, I'd like to wait for other tests to need these classes before moving them. Is that okay?

:raises: TestFail if device not found
"""
device, _ = ccw.get_first_device_identifiers(self.chpids, session)
if not device == self.expected_device_address:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using inline negation, please refer to https://www.python.org/dev/peps/pep-0008/#programming-recommendations(Use is not operator rather than not ... is. While both expressions are functionally identical, the former is more readable and preferred:...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)


virt_install_with_hostdev(vm_name, mdev_nodedev, target_address, disk)

session = vm.wait_for_login()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to start the vm before trying to loin?

Copy link
Contributor Author

@smitterl smitterl Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to start the vm before trying to loin?

No, the virt-install command boots the guest.

@smitterl smitterl force-pushed the virt_tools_single_commit branch 2 times, most recently from 8249f0d to dfa4178 Compare January 4, 2022 16:49
from virttest import virsh


class MdevHandler(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious that in terms of MdevHandler, would you like maintain it as local test module in hostdev_mdev.py , or it could be more generic module shared across test modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chunfuwen I think your question is covered in discussion above #3923 (comment)

@@ -0,0 +1,198 @@
import logging
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add 'LOG = log.getLogger('avocado.' + name)' and replace logging.xxx with LOG.xxx in the code. The current way does not log messages in the latest avocado. For details, please check #3833

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@smitterl smitterl force-pushed the virt_tools_single_commit branch from dfa4178 to 0dcd75d Compare January 21, 2022 16:18
@smitterl
Copy link
Contributor Author

Rerun after requested changes:

JOB ID     : f58d52f08ef6cf45371d843f36aee267ed7e2f8c
JOB LOG    : /root/avocado/job-results/job-2022-01-21T11.15-f58d52f/job.log
 (1/1) type_specific.io-github-autotest-libvirt.virt_install.hostdev.mdev.check_present_inside_guest: PASS (18.27 s)                                                                         
RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME   : 18.59 s

@smitterl smitterl force-pushed the virt_tools_single_commit branch from 0dcd75d to 3d05e37 Compare January 21, 2022 16:22
Copy link
Contributor

@chunfuwen chunfuwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@Yingshun Yingshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others LGTM


:param device_id: cssid.ssid.devno, e.g. 0.0.560a
:param session: guest session, command is run on host if None
:raises TestError: if the device can't be set online
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should 'online' be 'offline'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there's already a function set_device_online

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @smitterl ,I should speak full sentence to make the comment clearer.
This function is set_device_offline() which used to set the device offline. And from the code, we can see that it'll raise TestError if the device can't be set offline, but not online. So I mean, I think it's a typo here, and it should be like:

Suggested change
:raises TestError: if the device can't be set online
:raises TestError: if the device can't be set offline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it now @Yingshun You are right. I fixed it. Thank you!

@smitterl smitterl requested a review from Yingshun January 27, 2022 15:14
1. /virttools:
    Add new test type for tools from virt-manager repository; by
    using avocado-vt we get access to many useful test functions
    ready to use for qemu/libvirt testing. The test type assumes
    the same default setup as for tp-libvirt/libvirt and builds
    on top of that. During testing, switching from a bootstrapped
    libvirt environment to a bootstrapped virttools environment
    worked and the test case passed.
2. hostdev_mdev:
    Add a new test case.
    a. 'run': This virt-install test case is currently ccw device
              specific but other types on other platforms can be
              implemented by creating a subclass for the
              MdevHandler for the desired mdev_type.
    b. 'clean_up/sleep': The introduction of 1sec sleep is
              necessary to make sure setting the device offline will
              work. Using the usual 'wait_for' here seemed to
              overcomplicate the code.
    c. 'virt_install_with_hostdev': The function hardcodes several
              vm installation parameters. This is to keep the code
              simple at this point but can be changed in the future.
3. spell.ignore:
    Add command and device names used in ccw.py and hostdev_mdev.py.
4. ccw.py:
    Add a new function to set devices offline to reset them to their
    previous state. Test cases with real ccw devices usually assume
    the test environment is configured in a way that the first unused
    ccw device will be used for the test case, possibly in a
    destructive way. Some functions have been added return value 'True'
    on success to allow for usage in 'wait_for' constructions.
5. README.md:
    Add readme file to give a bit more context and intention for the
    new test type.

Signed-off-by: Sebastian Mitterle <[email protected]>
@smitterl smitterl force-pushed the virt_tools_single_commit branch from 3d05e37 to 3532df3 Compare January 28, 2022 09:31
Copy link
Contributor

@Yingshun Yingshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chunfuwen
Copy link
Contributor

comments had been addressed, let's merge it

@chunfuwen chunfuwen merged commit da8c84f into autotest:master Jan 28, 2022
@smitterl smitterl deleted the virt_tools_single_commit branch July 28, 2022 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
depend on The PR has dependency on other PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants